import { MusicRequest } from "../api/music.js"
import { parseLyric } from "./parseLysic.js"
export const actions = {
	//请求歌曲信息
	async getSong(context, id) {
		const result = await MusicRequest({
			url: "/song/detail",
			data: {
				ids: id,
			},
		})
		let song = result[1].data.songs[0]
		let music = {
			id,
			name: song.name,
			picUrl: song.al.picUrl,
			author: song.ar[0].name,
		}
		let res = await MusicRequest({
			url: "/song/url",
			data: {
				id: id,
			},
		})
		// 获取歌词
		let lyric = await MusicRequest({
			url: "/lyric",
			data: {
				id: id,
			},
		})
		if (lyric[1].data.lrc) {
			lyric = lyric[1].data.lrc.lyric
		} else {
			lyric = "暂无歌词"
		}

		let newlyric = parseLyric(lyric)
		music.src = res[1].data.data[0].url
		music.lyric = newlyric
		this.commit("upDateSong", music)
	},
}
